package com.guoranhao.web.resolver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * Description:对request中的userVo对像封装方法入参 
 * Copyright (c) Department of Research and Development/Beijing
 * All Rights Reserved.
 * @version 1.0  2016年9月22日 下午3:07:48  by 杨雷（yanglei@cloud-young.com）创建
 */
@Component
public class CustomAugmentResolver implements HandlerMethodArgumentResolver {
	
    @Autowired
    private CustomObjectMapper objectMapper;

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return false;
    }

    @Override
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) {
//        if (methodParameter.getParameterType().equals(UserBaseInfo.class)){
//            HttpServletRequest request = nativeWebRequest.getNativeRequest(HttpServletRequest.class);
//            return request.getAttribute("user");
//        }
        if (methodParameter.getParameterType().equals(CustomObjectMapper.class)){
            return objectMapper;
        }
        return null;
    }
}
